<?php

namespace app\common\model;

use think\Model;

class WithdrawAccount extends Model
{
    // 表名
    protected $name = 'withdraw_account';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    
    // 追加属性
    protected $append = [
        'status_text',
        'create_time_text',
        'update_time_text'
    ];
    

    const STATUS_Y = 1;
    const STATYS_N = 0;
    
    public static $_status = [
        self::STATUS_Y => '正常',
	    self::STATYS_N => '删除'
    ];
    
    public function getStatusList()
    {
    	return self::$_status;
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['create_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['update_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function user(){
    	return $this->belongsTo('user', 'user_id', 'id', '', 'left')->setEagerlyType(0);
    }
    
    public function bank(){
    	return $this->belongsTo('bank', 'bank_id', 'id', '', 'left')->setEagerlyType(0);
    }
}
